<div [@routerTransition]>

    <div class="content d-flex flex-column flex-column-fluid">

        <sub-header [title]="'Scheduling' | localize" [description]="'Scheduling' | localize">
            <div role="actions">
                <div class="btn-group dropdown" dropdown>
                    <button class="btn btn-primary dropdown-toggle icon-fabu" type="button" id="publishButton"
                        data-toggle="dropdown" dropdownToggle aria-haspopup="true" aria-expanded="false">
                        {{l('publishSchedule')}}
                    </button>
                    <div class="dropdown-menu" *dropdownMenu aria-labelledby="publishButton" x-placement="bottom-start">
                        <!-- *ngIf="schedulePublishList.length>0" -->
                        <a class="dropdown-item icon-fabu1" *ngIf="schedulePublishList" (click)="goPublish()">
                            {{l('publishSchedule')}}
                        </a>
                        <!-- <a class="dropdown-item icon-select" (click)="publishAll()">
                            {{l('publishAll')}}
                        </a> -->
                        <a class="dropdown-item icon-chehui1" (click)="withdrawAll()">
                            {{l('withdrawAll')}}
                        </a>
                    </div>
                </div>
                <button class="btn btn-primary" (click)="createSchedule()">
                    <i class="fa fa-plus"></i>
                    {{l("CreateSchedule")}}</button>
            </div>
        </sub-header>


        <div [class]="containerClass">
            <div class="card card-custom gutter-b">
                <div class="card-body">
                    <div class="row align-items-center">
                        <form class="horizontal-form" autocomplete="off">
                            <div class="m-form m-form--label-align-right">
                                <div class="row align-items-center m--margin-bottom-10">
                                    <div class="col-4">
                                        <div class="form-group m-form__group align-items-center">
                                            <label>{{l('name')}}</label>
                                            <div class="input-group">
                                                <input [(ngModel)]="filterText" name="filterText" autoFocus
                                                    class="form-control m-input" (keyup.enter)="getSchedule()"
                                                    [placeholder]="l('SearchWithThreeDot')" type="text">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-2">
                                        <div class="form-group m-form__group align-items-center">
                                            <label>&nbsp;</label>
                                            <div class="input-group">
                                                <button type="button" class="btn btn-primary"
                                                    [buttonBusy]="primengTableHelper.isLoading" (click)="getSchedule()">
                                                    <i class="la la-refresh"></i>
                                                    {{l("search")}}
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="row align-items-center">
                        <div class="primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
                            <p-table #dataTable (onLazyLoad)="getSchedule($event)" [value]="primengTableHelper.records"
                                [rows]="primengTableHelper.defaultRecordsCountPerPage"
                                [(selection)]="schedulePublishList" [paginator]="false" [lazy]="true"
                                [resizableColumns]="primengTableHelper.resizableColumns"
                                [responsive]="primengTableHelper.isResponsive">
                                <ng-template pTemplate="header">
                                    <tr>
                                        <th>{{l('Actions')}}</th>
                                        <th style="width: 5.0em">
                                            <!-- <p-tableRadioButton></p-tableRadioButton> -->
                                            <!-- <p-tableCheckbox></p-tableCheckbox> -->
                                        </th>
                                        <th style="width:5%">{{l('RecordId')}}</th>
                                        <th>{{l('name')}}</th>
                                        <!-- <th>{{l('thumbnail')}}</th> -->
                                        <th pSortableColumn="activeTime">
                                            {{l('startDate')}}
                                            <p-sortIcon field="activeTime"></p-sortIcon>
                                        </th>
                                        <th pSortableColumn="endTime">{{l('endDate')}}
                                            <p-sortIcon field="endTime"></p-sortIcon>
                                        </th>
                                        <th pSortableColumn="effectiveTime">{{l('PublishTime')}}
                                            <p-sortIcon field="effectiveTime"></p-sortIcon>
                                        </th>
                                        <th pSortableColumn="updateTime">{{l('UpdateTime')}}
                                            <p-sortIcon field="updateTime"></p-sortIcon>
                                        </th>
                                        <th style="width:35%;">{{l('description')}}</th>
                                        <th pSortableColumn="creationTime">
                                            {{l('CreationTime')}}
                                            <p-sortIcon field="creationTime"></p-sortIcon>
                                        </th>
                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="body" let-record let-i="rowIndex">
                                    <tr [pSelectableRow]="record" [attr.trid]="record.id">
                                        <td>
                                            <div class="btn-group dropdown" dropdown normalizePosition>
                                                <button class="dropdown-toggle btn btn-sm btn-primary"
                                                    data-toggle="dropdown" dropdownToggle aria-haspopup="true"
                                                    aria-expanded="false">
                                                    <i class="fa fa-cog"></i>
                                                    <span class="caret"></span> {{l("Actions")}}
                                                </button>
                                                <ul class="dropdown-menu" *dropdownMenu>
                                                    <li>
                                                        <a (click)="edit(record)"
                                                            class="icon-bianji dropdown-item">{{l('BasicSetup')}}</a>
                                                    </li>
                                                    <li>
                                                        <a (click)="goDetail(record)"
                                                            class="icon-yingyong dropdown-item">{{l('detail')}}</a>
                                                    </li>
                                                    <li>
                                                        <a (click)="deleteSchedule(record)"
                                                            class="icon-icon-test dropdown-item">{{l('Delete')}}</a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                        <td>
                                            <p-tableRadioButton [value]="record"></p-tableRadioButton>
                                            <!-- <p-tableCheckbox [value]="record"></p-tableCheckbox> -->
                                        </td>
                                        <td> {{transIndex(i)}}</td>
                                        <td>
                                            <span>{{record.name}}</span>
                                        </td>
                                        <!-- <td>
                                                <img [src]="fixFileUrl(record.iconUrl)" (error)="showEmpty($event)" />
                                            </td> -->
                                        <td>{{record.activeTime | date : "yyyy/MM/dd"}}</td>
                                        <td>{{record.endTime| date : "yyyy/MM/dd"}}</td>
                                        <td>{{record.effectiveTime| date : "yyyy/MM/dd"}}</td>
                                        <td>{{record.lastModificationTime| date : "yyyy/MM/dd"}}</td>
                                        <td>
                                            <span>{{record.description}}</span>
                                        </td>
                                        <td>{{record.creationTime| date : "yyyy/MM/dd"}}</td>
                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="emptymessage" let-records>
                                    <tr *ngIf="primengTableHelper.records">
                                        <td colspan="7">
                                            <img class="emptymessage"
                                                src="/assets/common/images/placeholder/productHolder.png" />
                                        </td>
                                    </tr>
                                </ng-template>
                            </p-table>
                            <div class="primeng-paging-container">
                                <p-paginator [rows]="primengTableHelper.defaultRecordsCountPerPage" #paginator
                                    (onPageChange)="getSchedule($event)"
                                    [totalRecords]="primengTableHelper.totalRecordsCount"
                                    [rowsPerPageOptions]="primengTableHelper.predefinedRecordsCountPerPage">
                                </p-paginator>
                                <span class="total-records-count">
                                    {{l('TotalRecordsCount', primengTableHelper.totalRecordsCount)}}
                                </span>
                            </div>
                        </div>
                    </div>
                </div>
                <div [ngClass]="{'hide':!toPublish,'float_panel':true,'beautyScroll':true}"
                    [ngStyle]="{'height':avalibleHeight}" *ngIf="toPublish">
                    <div class="panel_head">
                        <h3>{{l('publishSchedule')}}</h3>
                        <div class="text-right x">
                            <button (click)="toPublish=!toPublish">
                                <i class="icon-close"></i>
                            </button>
                        </div>
                    </div>
                    <div class="panel_body">
                        <form (ngSubmit)="doPublishSchedule()" name="publishConForm">
                            <div class="form-group">
                                <div class="radio-inline">
                                    <label class="radio">
                                        <input type="radio" name="publishType" [(ngModel)]="publishType" value="add">
                                        {{l('append')}}
                                        <span></span>
                                    </label>
                                    <label class="radio">
                                        <input type="radio" name="publishType" [(ngModel)]="publishType" value="update">
                                        {{l('update')}}
                                        <span></span>
                                    </label>
                                    <label class="radio">
                                        <input type="radio" name="publishType" [(ngModel)]="publishType" value="delete">
                                        {{l('withdraw')}}
                                        <span></span>
                                    </label>
                                    <label class="checkbox checkbox-primary">
                                        <input [(ngModel)]="informDevice" type="checkbox"
                                            name="informDevice" />{{l("informDevice")}}
                                        <span></span>
                                    </label>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="input-group">
                                    <input [(ngModel)]="treeFilter" name="treeFilterText" autoFocus
                                        class="form-control m-input" (keydown.enter)="filterTree($event)"
                                        [placeholder]="l('SearchWithThreeDot')" type="text">
                                    <span class="input-group-btn">
                                        <button class="btn btn-primary" type="button" (click)="filterTree()">
                                            <i class="icon-sousuo-sousuo"></i>
                                        </button>
                                    </span>
                                </div>
                            </div>

                            <div class="form-group beautyScroll"
                                [ngStyle]="{'max-height':'calc('+avalibleHeight+' - 253px)','padding-left':'20px'}">
                                <app-my-tree #myTree [config]="{'showId':true}" [(items)]="deviceTree">
                                </app-my-tree>
                                <h3 *ngIf="!deviceTree||deviceTree.length==0">{{l('NoData')}}</h3>
                            </div>

                            <div class="form-group text-right">
                                <button *ngIf="deviceTree&&deviceTree.length" type="submit"
                                    class="btn btn-primary">{{l('Publish')}}</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

        </div>
        <scheduleModal #scheduleModal (modalSave)="getSchedule()"></scheduleModal>
        <calendarModal #calendarModal></calendarModal>
    </div>
</div>